home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 May / may_2001.iso / intercd / root / Multimedia / ^DivX_Article / DivX / VFW4048src / src / DriverProc.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-18  |  5.9 KB  |  198 lines

  1.  
  2. /**************************************************************************
  3.  *                                                                        *
  4.  * This code is developed by Adam Li.  This software is an                *
  5.  * implementation of a part of one or more MPEG-4 Video tools as          *
  6.  * specified in ISO/IEC 14496-2 standard.  Those intending to use this    *
  7.  * software module in hardware or software products are advised that its  *
  8.  * use may infringe existing patents or copyrights, and any such use      *
  9.  * would be at such party's own risk.  The original developer of this     *
  10.  * software module and his/her company, and subsequent editors and their  *
  11.  * companies (including Project Mayo), will have no liability for use of  *
  12.  * this software or modifications or derivatives thereof.                 *
  13.  *                                                                        *
  14.  * Project Mayo gives users of the Codec a license to this software       *
  15.  * module or modifications thereof for use in hardware or software        *
  16.  * products claiming conformance to the MPEG-4 Video Standard as          *
  17.  * described in the Open DivX license.                                    *
  18.  *                                                                        *
  19.  * The complete Open DivX license can be found at                         *
  20.  * http://www.projectmayo.com/opendivx/license.php .                      *
  21.  *                                                                        *
  22.  **************************************************************************/
  23.  
  24. /************************************************************************
  25.  *
  26.  *  DriverProc.cpp, Main Driver Process
  27.  *
  28.  *  Copyright (C) 2000  DivX Networks
  29.  * 
  30.  *  Adam Li
  31.  *
  32.  *  DivX Advance Research Center <darc@projectmayo.com>
  33.  *
  34.  ************************************************************************/
  35.  
  36. // This is the main entrance and message loop of the codec driver.
  37. // It dispatchs the message, and calls the corresponding functions of the driver.
  38. // The maintains functions are in maintain.cpp and config_dialog.cpp. 
  39. // The encoder functions are in enc_engine.cpp.
  40. // The decoder functions are in dec_engine.cpp.
  41. // It initializes the lookup table for RGB<->YUV conversion. 
  42.  
  43. #include "StdAfx.h"
  44. #include "codec.h"
  45.  
  46. /**
  47.  * personalized messages for the decoder 
  48. **/
  49.  
  50. #define DIVXSET_POSTPROCESSING (ICM_USER+80) // set postprocessing level
  51.  
  52. /* These has to be global, since the windows open one codec instance 
  53. for configure, then use another codec instance for encoding. */
  54. long rc_period = 300;
  55. long bitrate = 780000;
  56. int search_range = 128;
  57. int max_quantizer = 15;
  58. int min_quantizer = 2;
  59.  
  60. __declspec(dllexport) LRESULT WINAPI DriverProc(DWORD dwDriverID, HDRVR hDriver, UINT uiMessage, LPARAM lParam1, LPARAM lParam2) 
  61. {
  62.     codec *cdx = (codec *)(UINT)dwDriverID;
  63.     ICOPEN *icinfo = (ICOPEN *)lParam2;
  64.     switch (uiMessage) {
  65.  
  66.         /****************************************
  67.  
  68.             decompress messages
  69.  
  70.         ****************************************/
  71.  
  72.         case ICM_DECOMPRESS:
  73.             return cdx->decDecode(lParam1, lParam2);
  74.  
  75.         case ICM_DECOMPRESS_GET_PALETTE:
  76.         case ICM_DECOMPRESS_SET_PALETTE:
  77.             return ICERR_UNSUPPORTED;
  78.  
  79.         case ICM_DECOMPRESS_QUERY:
  80.             return cdx->decQuery(lParam1, lParam2);
  81.  
  82.         case ICM_DECOMPRESS_GET_FORMAT:
  83.             return cdx->decGetFormat(lParam1, lParam2);
  84.  
  85.         case ICM_DECOMPRESS_BEGIN:
  86.             return cdx->decBegin(lParam1, lParam2);
  87.  
  88.         case ICM_DECOMPRESS_END:
  89.             return cdx->decEnd(lParam1, lParam2);
  90.  
  91.         // decoder settings messages
  92.  
  93.         case DIVXSET_POSTPROCESSING:
  94.             return cdx->decSetPostProcessing(lParam1, lParam2);
  95.  
  96.         /****************************************
  97.  
  98.             standard driver messages
  99.  
  100.         ****************************************/
  101.  
  102.         case DRV_LOAD:
  103.             return (LRESULT)1L;
  104.  
  105.         case DRV_FREE:
  106.             return (LRESULT)1L;
  107.  
  108.         case DRV_OPEN:
  109.             if (icinfo && icinfo->fccType != ICTYPE_VIDEO) return NULL;
  110.             cdx = new codec;
  111.             if (icinfo) icinfo->dwError = cdx ? ICERR_OK : ICERR_MEMORY;
  112.             return (LRESULT)(DWORD)(UINT) cdx;
  113.  
  114.         case DRV_CLOSE:
  115. //            delete(cdx); // this (occationally) causes problem at closing
  116.             return (LRESULT)1L;
  117.  
  118.         case DRV_DISABLE:
  119.         case DRV_ENABLE:
  120.             return (LRESULT)1L;
  121.  
  122.         case DRV_INSTALL:
  123.         case DRV_REMOVE:
  124.             return (LRESULT)DRV_OK;
  125.  
  126.         case DRV_QUERYCONFIGURE:    
  127.             return (LRESULT)1L; // does support drive configure with the about box
  128.  
  129.         case DRV_CONFIGURE:
  130.             return cdx->about(lParam1,lParam2);
  131.  
  132.         /****************************************
  133.  
  134.             state messages
  135.  
  136.         ****************************************/
  137.  
  138.         case ICM_ABOUT:
  139.             return cdx->about(lParam1,lParam2);
  140.  
  141.         case ICM_CONFIGURE:
  142.             return cdx->config(lParam1, lParam2);
  143.  
  144.         case ICM_GETSTATE:
  145.             if (lParam1 == NULL) return 0;
  146.             else return ICERR_OK;
  147.  
  148.         case ICM_SETSTATE:
  149.             return 0;
  150.  
  151.         case ICM_GET:
  152.             return 0;
  153.  
  154.         case ICM_GETQUALITY:
  155.         case ICM_SETQUALITY:
  156.         case ICM_GETDEFAULTQUALITY:
  157.         case ICM_GETDEFAULTKEYFRAMERATE:
  158.             return ICERR_UNSUPPORTED;
  159.  
  160.         case ICM_GETINFO:
  161.             return cdx->getInfo(lParam1, lParam2);
  162.  
  163.         /****************************************
  164.  
  165.             compression messages
  166.  
  167.         ****************************************/
  168.  
  169.         case ICM_COMPRESS_QUERY:
  170.             return cdx->encQuery(lParam1, lParam2);
  171.  
  172.         case ICM_COMPRESS_GET_FORMAT:
  173.             return cdx->encGetFormat(lParam1, lParam2);
  174.  
  175.         case ICM_COMPRESS_GET_SIZE:
  176.             return cdx->encGetSize(lParam1, lParam2);
  177.  
  178.         case ICM_COMPRESS_FRAMES_INFO:
  179.             return cdx->encFramesInfo(lParam1, lParam2);
  180.  
  181.         case ICM_COMPRESS_BEGIN:
  182.             return cdx->encBegin(lParam1, lParam2);
  183.  
  184.         case ICM_COMPRESS:
  185.             return cdx->encEncode(lParam1, lParam2);
  186.  
  187.         case ICM_COMPRESS_END:
  188.             return cdx->encEnd(lParam1, lParam2);
  189.  
  190.   }
  191.  
  192.     if (uiMessage < DRV_USER)
  193.         return DefDriverProc(dwDriverID, hDriver, uiMessage, lParam1, lParam2);
  194.     else
  195.         return ICERR_UNSUPPORTED;
  196. }
  197.  
  198.